#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using Ease.EaseNode.Runtime.Param;
using UnityEngine;

namespace Ease.EaseNode.Runtime
{
    public abstract class BaseEaseNodeDataState : IEaseNodeDataState
    {
        public virtual Vector2 NodePos
        {
            get => Data.NodeInfo.NodePos;
            set => Data.NodeInfo.NodePos = value;
        }

        public virtual string Key
        {
            get => Data.Key;
            set { }
        }

        public virtual List<PortConfig> InputConfigs => Data.NodeInfo.InputConfigs;

        public virtual List<PortConfig> OutputConfigs => Data.NodeInfo.OutputConfigs;

        public virtual List<PortInfo> InputInfos => Data.NodeInfo.InputInfos;

        public virtual List<PortInfo> OutputInfos => Data.NodeInfo.OutputInfos;

        public virtual void AddInputInfos(string key, string value)
        {
            Data.NodeInfo.AddInputInfos(key, value);
        }

        public virtual void RemoveInputInfos(string key, string value)
        {
            Data.NodeInfo.RemoveInputInfos(key, value);
        }

        public virtual void AddOutputInfos(string key, string value)
        {
            Data.NodeInfo.AddOutputInfos(key, value);
        }

        public virtual void RemoveOutputInfos(string key, string value)
        {
            Data.NodeInfo.RemoveOutputInfos(key, value);
        }

        public abstract event Action<BaseChangeParam> OnValueChangeEvent;
        public abstract void OnValueChange(BaseChangeParam param);
        public abstract void OnCreate();
        public abstract void OnDestroy();

        public NodeState CurrentNodeState { get; set; }

        public abstract IEaseNodeData Data { get; set; }
    }

    public abstract class BaseEaseNodeDataState<T> : BaseEaseNodeDataState where T : class, IEaseNodeData
    {
        protected T data;

        public override IEaseNodeData Data
        {
            get => data;
            set => data = (T)value;
        }

        public override void OnCreate()
        {
        }

        public override void OnDestroy()
        {
            data = null;
        }

        public override void OnValueChange(BaseChangeParam param)
        {
            if (param is StateChangeParam a)
            {
                CurrentNodeState = a.newState;
            }
        }
    }
}
#endif